home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE05 / CLINIC / EDITMENU.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-10-19  |  2.5 KB  |  101 lines

  1. unit Editmenu;
  2. {$X+}
  3.  
  4. interface
  5.  
  6. uses
  7.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  8.   Forms, Dialogs, DBCtrls, StdCtrls, Mask, Grids, DBGrids, DB, DBTables,
  9.   Menus, ClipBrd;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     MainMenu1: TMainMenu;
  14.     Edit1: TMenuItem;
  15.     Paste1: TMenuItem;
  16.     Copy1: TMenuItem;
  17.     Cut1: TMenuItem;
  18.     Undo1: TMenuItem;
  19.     Delete1: TMenuItem;
  20.     DataSource1: TDataSource;
  21.     Table1: TTable;
  22.     DBGrid1: TDBGrid;
  23.     Edit2: TEdit;
  24.     DBEdit1: TDBEdit;
  25.     Label1: TLabel;
  26.     Label2: TLabel;
  27.     Label3: TLabel;
  28.     Memo1: TMemo;
  29.     Label4: TLabel;
  30.     DBMemo1: TDBMemo;
  31.     Label5: TLabel;
  32.     N1: TMenuItem;
  33.     procedure EditMenuClick(Sender: TObject);
  34.     procedure MenuClick(Sender: TObject);
  35.   private
  36.     { This variable gets pre-set to nil (as do all others) }
  37.     EditCtl: TCustomEdit;
  38.   end;
  39.  
  40. var
  41.   Form1: TForm1;
  42.  
  43. implementation
  44.  
  45. {$R *.DFM}
  46.  
  47. procedure TForm1.EditMenuClick(Sender: TObject);
  48. var
  49.   Loop: Byte;
  50. begin
  51.   EditCtl := nil;
  52.   if ActiveControl is TCustomEdit then
  53.     EditCtl := ActiveControl as TCustomEdit
  54.   else
  55.     { When editing in a grid, the grid is the active control, not the }
  56.     { in-place editor, so we need to find the editor in the grid }
  57.     if (ActiveControl is TCustomGrid) then
  58.       with TCustomGrid(ActiveControl) do
  59.         { If grid owns any controls, cycle through them checking for editor }
  60.         if ControlCount > 0 then
  61.           for Loop := 0 to Pred(ControlCount) do
  62.             if Controls[Loop] is TInPlaceEdit then
  63.               { Editor is visible when being used }
  64.               if Controls[Loop].Visible then
  65.               begin
  66.                 EditCtl := TInPlaceEdit(Controls[Loop]);
  67.                 Break;
  68.               end;
  69.   if Assigned(EditCtl) then
  70.   begin
  71.     Undo1.Enabled := Bool(EditCtl.Perform(em_CanUndo, 0, 0));
  72.     Cut1.Enabled := EditCtl.SelLength > 0;
  73.     Copy1.Enabled := Cut1.Enabled;
  74.     Paste1.Enabled := ClipBoard.AsText <> '';
  75.     Delete1.Enabled := EditCtl.SelLength > 0;
  76.   end
  77.   else
  78.   begin
  79.     Undo1.Enabled := False;
  80.     Cut1.Enabled := False;
  81.     Copy1.Enabled := False;
  82.     Paste1.Enabled := False;
  83.     Delete1.Enabled := False;
  84.   end;
  85. end;
  86.  
  87. procedure TForm1.MenuClick(Sender: TObject);
  88. begin
  89.   if Assigned(EditCtl) then
  90.     with EditCtl do
  91.       case (Sender as TComponent).Tag of
  92.         1: Perform(em_Undo, 0, 0);
  93.         2: CutToClipBoard;
  94.         3: CopyToClipBoard;
  95.         4: PasteFromClipBoard;
  96.         5: ClearSelection;
  97.       end;
  98. end;
  99.  
  100. end.
  101.